<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/jsp/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<title>一级代理商注册</title>
<script src="${ctxStatic}/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/plugins/h+/css/style.css" rel="stylesheet">
<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/plugins/h+/css/flower_css.css" />

</head>
<style>
.hdzctitle{
	display:inline-block;
	background:#2cc484;
	color:#fff;
	width:160px;
	height:30px;
	line-height:30px;
	margin-top:10px;
	margin-bottom:30px;
}
.djzhmmspan{
	background: #2cc484;
    border-radius: 5px;
    color: #fff;
    cursor: pointer;
    padding: 5px 15px;
}
.djzhmmspan:hover{
	background: #258b60;
}
</style>
<body style="background:#ededed">

<style>
.downloadspan{
	position:absolute;
	top:92px;
	left:57%;
	color:#f00;
}
</style>
<header class="zcheader">
	<!-- <img src="../resources/image/zc_logo.png" width="40"/> -->
</header>

<div class="zcsection" style="width: 755px;">
	<div class="zcsec_headimg" style="text-align:center;">
    	<span class="hdzctitle">一级代理商注册</span>
    </div>
    <span class="downloadspan">如果您无法注册，请下载谷歌浏览器。点此下载<a href="http://dlsw.baidu.com/sw-search-sp/soft/9d/14744/ChromeStandalone_47.0.2526.106_Setup.1450323126.exe" style="text-decoration:underline;">下载地址</a></span>
    <form class="foam-form" style="margin-left: 20px;" id="form"   accept-charset="UTF-8" onsubmit="document.charset='UTF-8';"> 
        <div class="zcsec_hdxx">
            <div class="zc_ggysdiv">
                <label>代理商名称：</label>&nbsp;&nbsp;
                <input type="text" placeholder="" id="txt_agnetName" name="agnetName" >
            </div>
        	<div class="zc_ggysdiv">
                <label>登录账户：</label>&nbsp;&nbsp;
                <input type="text" placeholder="" id="txt_loginName" name="loginName" >&nbsp;&nbsp;
            	 <span class="hqyzmspan" onclick="checkLoginName()">检验用户名是否可用</span>     
            </div>
            <div class="zc_ggysdiv">
                <label>手机号码：</label>&nbsp;&nbsp;
                <input type="text" placeholder="请输入手机号" id="txt_phone" name="phone">&nbsp;&nbsp;
                <span class="hqyzmspan msgs" onclick="getNumber()">获取验证码</span>
            </div>
            <div class="zc_ggysdiv">
                <label>验证码：</label>&nbsp;&nbsp;
                <input type="text" id="txt_number" name="shop_number">
            </div>
            <div class="zc_ggysdiv">
                <label>登录密码：</label>&nbsp;&nbsp;
                <input type="password" id="txt_psw" name="pwd">
            </div>
            <div class="zc_ggysdiv">
                <label>重复登录密码：</label>&nbsp;&nbsp;
                <input type="password" onblur="checkPsw()" id="txt_repsw" name="repsw">
            </div>
           <!--  <div class="zc_ggysdiv">
             <label>所属区域：</label>&nbsp;&nbsp;
                <select id="S1"  onchange="select2()" >
                </select>&nbsp;&nbsp;
                <select id="S2" name="cityId" onchange="select3()">
                </select>&nbsp;&nbsp;
                <select id="S3" name="areaId">
                </select>&nbsp;
            </div>
            <div class="zc_ggysdiv">
                <label>详细地址：</label>&nbsp;&nbsp;
                <input type="text" id="txt_addr" name="addr">
            </div>     -->
            <div class="" style="text-align: center;">
                <a href="javascript:;" class="zc_zhxxxyb" onclick="check2()" id="loginInfo" style="margin-top:40px;display: inline-block;">确定</a>
                &nbsp;&nbsp;<a href="javascript:;" class="zc_zhxxxyb" onclick="doBack2()" id="doBack" style="margin-top:40px;display: inline-block;">返回</a>
            </div>
            <%--<a href="javascript:;" class="zc_zhxxxyb" onclick="check2()" id="loginInfo" style="margin-top:40px;">确定</a>--%>
            <%--<a href="javascript:;" class="zc_zhxxxyb" onclick="doBack2()" id="doBack" style="margin-top:40px;">返回</a>--%>
        </div>
    </form>
</div>
<script type="text/javascript">
	var txt_number="";
	var pswFlag=false;
function checkPsw(){
	var psw=$("#txt_psw").val();
	var repsw=$("#txt_repsw").val();
	if(psw==repsw){
		pswFlag=true;
	}else{
	alert("两次密码不一致");
	
	}
}

//获取验证码
function getNumber() {
	var txt_phone=$("#txt_phone").val();
	if (txt_phone.length!=0) {
        reg = /^(13|15|17|18)\d{9}$/;
        if (!reg.test(txt_phone)) {
            alert("对不起，您输入的手机号格式不正确!");
        } else {
            $.ajax({
                type : "post",
                url : "${pageContext.request.contextPath}/api/reg/getNumber.ac?phoneNumber="+txt_phone+"&isNew=true",
                success : function(result) {
                    if(result == "true") {
                        dosend();
                    } else {
                        alert("你输入的手机号已经注册,可以选择找回密码！")
                    }
                }
            });
        }
	} else {
	    alert("请填写手机号");
	}
}

//提交检验
function check2(){
    var reg =/^[\u4E00-\u9FA5A-Za-z0-9\#-]+$/;
    var reg_1 = /^(13|15|17|18)\d{9}$/;
    var reg_2=/^[0-9a-zA-Z]*$/g;
    var txt_agnetName=$("#txt_agnetName").val();
    var txt_loginName=$("#txt_loginName").val();
    var txt_phone=$("#txt_phone").val();
    var txt_number=$("#txt_number").val();
    var txt_psw=$("#txt_psw").val();
    var txt_repsw=$("#txt_repsw").val();


    txt_phone=$.trim(txt_phone);
    txt_number=$.trim(txt_number);
    txt_psw=$.trim(txt_psw);
    txt_repsw=$.trim(txt_repsw);
    txt_agnetName=$.trim(txt_agnetName);

	if(txt_agnetName==""){
        alert("请填写代理商名称！");
        return false;
	} else if(txt_loginName==""){
        alert("请填写登录账户！");
        return false;
    }else if(txt_phone==""){
        alert("请填写手机号！");
        return false;
	} else if(txt_number==""){
        alert("请填写验证码！");
        return false;
	} else if(txt_psw==""){
        alert("请填写登陆密码!");
        return false;
	} else if(txt_repsw==""){
        alert("请再填写登陆密码！");
        return false;
	} else if(txt_psw!=txt_repsw){
        alert("两次密码不一致");
        return false;
	} else if(!reg_1.test(txt_phone)){
        alert("手机号不合法，请输入合法字符");
        return false;
	} else if(!reg_2.test(txt_psw)){
        alert("密码格式不合法，请输入合法字符");
        return false;
	} else if(!reg.test(txt_agnetName)){
        alert("代理商名称格式不合法，请输入合法字符");
        return false;
	}

    var button = $("#loginInfo");
    button.css("background","#787878");
    button.text("请稍等");

    $.ajax({
        type : "post",
        async:false,
        data:$('#form').serialize(),
        url : '${pageContext.request.contextPath}/api/reg/regAgent.ac',
        success : function(result) {
            if(result == 0) {
                alert("注册成功，请等待管理员审核!");
                location.href="${pageContext.request.contextPath}/login/login_v2.jsp";
            } else if(result == 1) {
                alert("该手机号已经注册!");
            } else if(result == 2) {
                alert("该用户名已存在!");
            } else if(result == 3) {
                alert("验证码错误或者手机号和验证码不匹配!");
            } else {
                alert("注册失败，请重新尝试！");
            }

            var button = $("#loginInfo");
            button.css("background","");
            button.text("确定");
        }
    });
}

function checkLoginName() {
    var loginName=$("#txt_loginName").val();
    if(loginName==""){
        alert("请填写登录名！");
        return false;
    }

    $.ajax({
        type : "post",
        async:false,
        url : "${pageContext.request.contextPath}/api/reg/checkLoginName.ac?loginName="+loginName,
        success : function(result) {
            alert(jQuery.parseJSON(result));
        }
	});
}

function doBack2() {
    window.location.href="${pageContext.request.contextPath}/login/login_v2.jsp";
}

var Foamtime=true;
	function dosend(){
		//获取短信验证码
				var time=60;
				var code=$(".msgs");
				if (Foamtime) {
					Foamtime=false;
					code.addClass("msgs1");
					var t=setInterval(function () {
						time--;
						code.html(time+"秒");
						if (time == 0) {
							clearInterval(t);
						code.html("重新获取");
							Foamtime=true;
						code.removeClass("msgs1");
						}
					},1000);
				}
	}
</script>

</body>
</html>